package Sort;

public class ShellSort {
    public void Sort(int[] array)
    {
        int gap = array.length;
        while(gap > 1)
        {
            gap /= 2;
            shell(array, gap);
        }
    }

    private void shell(int[] array, int gap) {
         for(int i = gap; i < array.length; i++)
         {
             int tmp = array[i];
             int j = i - gap;
             for(; j >= 0; j -= gap)
             {
                 if(array[j] > tmp)
                 {
                     array[j + gap] = array[j];
                 }
                 else {
                     break;
                 }
             }
             array[gap + j] = tmp;
         }
    }
}
